From 45716c575ebeb4c53c266fd463b56ea1ca7b13d9 Mon Sep 17 00:00:00 2001 From: robertl Date: Thu, 30 Jun 2005 22:51:45 +0000 Subject: [PATCH] From Etienne: Vito cleansps. Misc warning fixes. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@1268 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/an1.c | 9 ++- gpsbabel/bcr.c | 5 +- gpsbabel/defs.h | 6 +- gpsbabel/maggeo.c | 2 - gpsbabel/mapsource.c | 4 +- gpsbabel/pathaway.c | 30 +++++---- gpsbabel/vecs.c | 1 - gpsbabel/vitosmt.c | 152 +++++++++++++++++++++++++++---------------- 8 files changed, 127 insertions(+), 82 deletions(-) diff --git a/gpsbabel/an1.c b/gpsbabel/an1.c index 63035f4c7..cb98a17a7 100644 --- a/gpsbabel/an1.c +++ b/gpsbabel/an1.c @@ -277,6 +277,7 @@ static an1_waypoint_record *Alloc_AN1_Waypoint( ) { result = (an1_waypoint_record *)xcalloc( sizeof(*result), 1 ); result->base.copy = Copy_AN1_Waypoint; result->base.destroy = Destroy_AN1_Waypoint; + return result; } static an1_vertex_record *Alloc_AN1_Vertex(); @@ -297,6 +298,7 @@ static an1_vertex_record *Alloc_AN1_Vertex() { result = (an1_vertex_record *)xcalloc( sizeof( *result), 1 ); result->base.copy = Copy_AN1_Vertex; result->base.destroy = Destroy_AN1_Vertex; + return result; } @@ -320,6 +322,7 @@ static an1_line_record *Alloc_AN1_Line( ) { result = (an1_line_record *)xcalloc( sizeof(*result), 1 ); result->base.copy = Copy_AN1_Line; result->base.destroy = Destroy_AN1_Line; + return result; } @@ -451,7 +454,7 @@ static void Write_AN1_Line( FILE *f, an1_line_record *line ) { len = strlen( line->name ); WriteShort( f, len ); WriteString( f, line->name ); - WriteShort( f, line->lineweight ); + WriteShort( f, (short) line->lineweight ); WriteLong( f, line->linestyle ); WriteLong( f, line->linecolor ); WriteLong( f, line->unk5 ); @@ -507,7 +510,7 @@ static void Read_AN1_Header( FILE *f ) { static void Write_AN1_Header( FILE *f ) { WriteShort( f, 11557 ); - WriteShort( f, atoi( output_type ) ); + WriteShort( f, (short) atoi( output_type ) ); } static void Read_AN1_Bitmaps( FILE *f ) { @@ -632,7 +635,7 @@ static void Read_AN1_Lines( FILE *f ) { rte_head = route_head_alloc(); rte_head->an1_extras = (an1_base *)(void *)rec; route_add_head(rte_head); - for (j = 0; j < rec->pointcount; j++ ) { + for (j = 0; j < (unsigned) rec->pointcount; j++ ) { vert = Alloc_AN1_Vertex(); Read_AN1_Vertex( f, vert ); diff --git a/gpsbabel/bcr.c b/gpsbabel/bcr.c index 0ef698e81..9f4a54b47 100644 --- a/gpsbabel/bcr.c +++ b/gpsbabel/bcr.c @@ -395,8 +395,7 @@ bcr_route_header(const route_head *route) char buff[128], symbol[32]; curr_rte_num++; - if (curr_rte_num != target_rte_num) return; - + if (curr_rte_num != target_rte_num) return; bcr_write_line(fout, "[CLIENT]", NULL, NULL); /* client section */ @@ -481,7 +480,7 @@ bcr_data_write(void) if (rtenum_opt != NULL) { target_rte_num = atoi(rtenum_opt); - if ((target_rte_num > route_count()) || (target_rte_num < 1)) + if (((unsigned)target_rte_num > route_count()) || (target_rte_num < 1)) fatal(MYNAME ": invalid route number %d (1..%d))!\n", target_rte_num, route_count()); } diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 72c5ce53a..afdb0c510 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -71,8 +71,9 @@ typedef enum { } gpsdata_type; typedef enum { - fix_unknown, - fix_2d, + fix_unknown=-1, + fix_none=0, + fix_2d=1, fix_3d, fix_dgps, fix_pps @@ -556,6 +557,7 @@ char *strsub(const char *s, const char *search, const char *replace); char *gstrsub(const char *s, const char *search, const char *replace); void rtrim(char *s); signed int get_tz_offset(void); +time_t mkgmtime(struct tm *t); time_t current_time(void); signed int month_lookup(const char *m); const char *get_cache_icon(const waypoint *waypointp); diff --git a/gpsbabel/maggeo.c b/gpsbabel/maggeo.c index f94960107..382719d82 100644 --- a/gpsbabel/maggeo.c +++ b/gpsbabel/maggeo.c @@ -125,7 +125,6 @@ static void maggeo_waypt_pr(const waypoint *waypointp) { char obuf[4096]; - char dtbuf[10]; double ilon, ilat; double lon, lat; int lon_deg, lat_deg; @@ -216,7 +215,6 @@ strconsume(char *instr, int *eaten) const char *origstr = instr; char *s = instr; char *e = instr; - int ct; while (e && *e && *e != ',') *e++; diff --git a/gpsbabel/mapsource.c b/gpsbabel/mapsource.c index f637cb0ea..0a913cc88 100644 --- a/gpsbabel/mapsource.c +++ b/gpsbabel/mapsource.c @@ -446,12 +446,12 @@ mps_fileHeader_w(FILE *mps_file, int mps_ver) strcpy(hdr+7,"Oct 20 1999"); strcpy(hdr+19,"12:50:33"); if (mps_ver == 4) { - hdr[1] = 0x96; /* equates to V4.06 */ + hdr[1] = (char) 0x96; /* equates to V4.06 */ strcpy(hdr+7,"Oct 22 2001"); strcpy(hdr+19,"15:45:33"); } if (mps_ver == 5) { - hdr[1] = 0xF4; /* equates to V5.0 */ + hdr[1] = (char) 0xF4; /* equates to V5.0 */ strcpy(hdr+7,"Jul 3 2003"); strcpy(hdr+19,"08:35:33"); } diff --git a/gpsbabel/pathaway.c b/gpsbabel/pathaway.c index fd779078c..92580d86d 100644 --- a/gpsbabel/pathaway.c +++ b/gpsbabel/pathaway.c @@ -79,22 +79,24 @@ is_fatal(int is, const char *msg, ... ) #if PPDB_DEBUG static void -internal_debug(const char *filename, int fileline, const char *format, ... ) +internal_debug1(const char *filename, int fileline) +{ + static int ct=1; + printf("DBG(%d): file %s, line %d: ", ct++, filename, fileline); +} +static void +internal_debug2(const char *format, ... ) { va_list args; - char *buff; - static int ct; - - buff = (char *) xmalloc(1024); + va_start(args, format); - vsnprintf(buff, 1023, format, args); - printf("DBG(%d): %s in file %s, line %d\n", ct++, buff, filename, fileline); + vprintf(format, args); + puts(""); va_end(args); - xfree(buff); } -#define DBG(fmt, args...) internal_debug (__FILE__, __LINE__, fmt, ## args ) +#define DBG internal_debug1(__FILE__, __LINE__);internal_debug2 #else -#define DBG(fmt, args...) +#define DBG # ; #endif @@ -131,8 +133,8 @@ char *ppdb_strcat(char *dest, char *src, char *def, int *size) #define STR_POOL_SIZE 16 /* !!! any power of 2 !!! */ -static char *str_pool[STR_POOL_SIZE] = {}; -static size_t str_pool_s[STR_POOL_SIZE] = {}; +static char *str_pool[STR_POOL_SIZE]; +static size_t str_pool_s[STR_POOL_SIZE]; static int str_poolp = -1; void str_pool_init(void) @@ -220,7 +222,7 @@ char *ppdb_fmt_float(const double val) char *ppdb_fmt_degrees(char dir, double val) { char *str = str_pool_get(32); - int deg = abs(val); + int deg = fabs(val); double min = 60.0 * (fabs(val) - deg); int power = 0; double fx = min; @@ -602,7 +604,7 @@ static void ppdb_write_wpt(const waypoint *wpt) buff = ppdb_strcat(buff, tmp, "", &len); len = strlen(buff) + 1; - rec = new_Record(0, 0, ct++, len, (const ubyte *) buff); + rec = new_Record(0, 0, (udword)ct++, (uword)len, (const ubyte *) buff); if (rec == NULL) fatal(MYNAME ": libpdb couldn't create record\n"); diff --git a/gpsbabel/vecs.c b/gpsbabel/vecs.c index 02c8bb51d..cbd7bf9b5 100644 --- a/gpsbabel/vecs.c +++ b/gpsbabel/vecs.c @@ -726,7 +726,6 @@ disp_formats(int version) { vecs_t **svp; vecs_t *vec; - style_vecs_t *svec; int i, vc = 0; switch(version) { diff --git a/gpsbabel/vitosmt.c b/gpsbabel/vitosmt.c index fe51c783c..562aeab04 100644 --- a/gpsbabel/vitosmt.c +++ b/gpsbabel/vitosmt.c @@ -27,15 +27,17 @@ #define MYNAME "vitosmt" #include "defs.h" -FILE *infile =0; -FILE *ofs =0; -unsigned long count =0; - -const size_t vitosmt_headersize =24; -const size_t vitosmt_datasize =64; -const double mile2km =1.609344; /* mile/h to kilometer/h */ -const double kts2mps =0.51444444444444444; /* knots to m/s */ -const double mph2mps =0.447039259; /* mile/h to m/s */ +static FILE *infile =0; +static FILE *ofs =0; +static long count =0; + +const long vitosmt_version =2; +const long vitosmt_subversion =1000; +const size_t vitosmt_headersize =24; +const size_t vitosmt_datasize =64; +const double mile2km =1.609344; /* mile/h to kilometer/h */ +const double kts2mps =0.5144444444444444444; /* knots to m/s */ +const double mph2mps =0.447039259; /* mile/h to m/s */ static unsigned long ReadLong(FILE * f) @@ -75,7 +77,7 @@ Skip(FILE * f, fseek(f, distance, SEEK_CUR); } -void +static void WriteDouble(void* ptr, double d) { unsigned char result[8]="\0\0\0\0\0\0\0\0"; @@ -102,7 +104,11 @@ rd_deinit(void) static void vitosmt_read(void) { - unsigned short version =0; + long version =0; + long subversion =0; + long check1 =-1; + long check2 =-2; + long check3 =-3; unsigned short stringlen =0; route_head *route_head =0; waypoint *wpt_tmp =0; @@ -119,18 +125,40 @@ vitosmt_read(void) unsigned char gpsvalid =0; unsigned char gpssats =0; int serial =0; + xml_tag * xml_curr =0; char buffer[80] ="\0"; /* * 24 bytes header */ - version = ReadLong(infile); /* 2 */ - ReadLong(infile); /* 1000 */ - count = ReadLong(infile); /* 600 */ - ReadLong(infile); /* 0 */ - ReadLong(infile); /* 599 */ - ReadLong(infile); /* 600 */ + version = ReadLong(infile); /* 2 */ + subversion = ReadLong(infile); /* 1000 */ + count = ReadLong(infile); /* n */ + check1 = ReadLong(infile); /* 0 */ + check2 = ReadLong(infile); /* n-1 */ + check3 = ReadLong(infile); /* n */ + + if (version!=vitosmt_version) { + + fatal("%s (%d) reading file. Unsupported version %ld.%ld\n", + MYNAME, __LINE__, version, subversion ); + } + + if (subversion!=vitosmt_subversion) { + warning("%s (%d) reading file. Unsafe version %ld.%ld\n", + MYNAME, __LINE__, version, subversion ); + } + + if ((count!=check3) || + (check1!=count-1) || + (check2!=0) || + (check3!=count) ) { + + fatal("%s (%d) reading file. Invalid file header\n", + MYNAME, __LINE__ ); + + } while (count) { /* @@ -138,6 +166,8 @@ vitosmt_read(void) */ if (feof(infile)||ferror(infile)) { + warning("%s (%d) reading file. Unexpected end of file %s\n", + MYNAME, __LINE__, strerror(errno) ); break; } @@ -181,22 +211,26 @@ vitosmt_read(void) GPS Fix data */ if (gpsvalid&0x7) { - - /* */ + if (gpsfix==0) + wpt_tmp->fix =fix_none; if (gpsfix&0x8) - wpt_tmp->fix = fix_2d; + wpt_tmp->fix =fix_2d; else if (gpsfix&0x10) - wpt_tmp->fix = fix_3d; + wpt_tmp->fix =fix_3d; else if (gpsfix&0x20) - wpt_tmp->fix = fix_dgps; + wpt_tmp->fix =fix_dgps; + else + wpt_tmp->fix =fix_unknown; /* */ wpt_tmp->sat = gpssats; } + else + wpt_tmp->fix =fix_unknown; if (doing_wpts) /* process as waypoints */ { - waypt_add(wpt_tmp); + waypt_add(wpt_tmp); } else if (doing_rtes) /* process as route */ { @@ -224,7 +258,7 @@ vitosmt_read(void) static void wr_init(const char *fname) { - warning(MYNAME ":format is experimental and may crash Vito Navigator II.\n"); + warning(MYNAME " write: format is experimental and may crash Vito Navigator II.\n"); ofs = xfopen(fname, "wb", MYNAME); } @@ -243,6 +277,7 @@ vitosmt_waypt_pr(const waypoint *waypointp) struct tm* tmstructp =0; double seconds =0; double worknum =0; + xml_tag* xmltagp =0; ++count; workbuffer = xcalloc(vitosmt_datasize,1); @@ -251,7 +286,8 @@ vitosmt_waypt_pr(const waypoint *waypointp) position += sizeof(double); WriteDouble(&workbuffer[position], (M_PI*waypointp->longitude)/180 ); position += sizeof(double); - WriteDouble(&workbuffer[position], waypointp->altitude ); + if ( waypointp->altitude-1 > unknown_alt) + WriteDouble(&workbuffer[position], waypointp->altitude ); position += sizeof(double); tmstructp = gmtime(&waypointp->creation_time); @@ -267,54 +303,60 @@ vitosmt_waypt_pr(const waypoint *waypointp) position += sizeof(double); /* speed */ - WriteDouble(&workbuffer[position], waypointp->speed / mph2mps ); + if (waypointp->speed>0) + WriteDouble(&workbuffer[position], waypointp->speed / mph2mps ); position += sizeof(double); /* course */ - WriteDouble(&workbuffer[position], waypointp->course ); + if ((waypointp->course>=-360.0)&&(waypointp->course<=360.0)) + WriteDouble(&workbuffer[position], waypointp->course ); position += sizeof(double); - /* pdop */ - WriteDouble(&workbuffer[position], waypointp->pdop ); + if (waypointp->pdop>0) + WriteDouble(&workbuffer[position], waypointp->pdop ); position += sizeof(double); /* fix type */ - switch (waypointp->fix) { - case fix_dgps: - workbuffer[position++] = (unsigned char) 0x20; - break; - case fix_3d: - workbuffer[position++] = (unsigned char) 0x10; - break; - case fix_2d: - workbuffer[position++] = (unsigned char) 0x08; - break; - default: - workbuffer[position++] = (unsigned char) 0; - break; + switch (waypointp->fix) + { + case fix_2d: + workbuffer[position++] = 0x08; + break; + case fix_3d: + workbuffer[position++] = 0x10; + break; + case fix_dgps: + workbuffer[position++] = 0x20; + break; + default: + workbuffer[position++] = 0; + break; } + + /* Assume position is valid */ + workbuffer[position++] = 0x07; - workbuffer[position++] = 0x7; - workbuffer[position++] = (unsigned char) waypointp->sat; + if ((waypointp->sat>0)&&(waypointp->sat<128)) + workbuffer[position++] = waypointp->sat; + else + workbuffer[position++] = 0; if (fwrite(workbuffer,vitosmt_datasize,1,ofs)!=1) { - fatal("%s writing output file. Error was '%s'.\n", - MYNAME, strerror(errno)); + fatal("%s (%d) writing output file. Error was '%s'.\n", + MYNAME, __LINE__, strerror(errno)); } xfree(workbuffer); } -void +static void vitosmt_write(void) { time_t now = 0; - const unsigned short version =2; - const unsigned short subversion =1000; unsigned char * workbuffer =0; size_t position =0; @@ -328,8 +370,8 @@ vitosmt_write(void) memset(workbuffer,0,vitosmt_headersize); if (fwrite(workbuffer,vitosmt_headersize,1,ofs)!=1) { - fatal("%s writing output file. Error was '%s'.\n", - MYNAME, strerror(errno)); + fatal("%s (%d) writing output file. Error was '%s'.\n", + MYNAME, __LINE__, strerror(errno)); } if (doing_wpts) /* process as waypoints */ @@ -347,9 +389,9 @@ vitosmt_write(void) /* write the complete the header */ - le_write32(&workbuffer[position],version); + le_write32(&workbuffer[position],vitosmt_version); position += sizeof(gbuint32); - le_write32(&workbuffer[position],subversion); + le_write32(&workbuffer[position],vitosmt_subversion); position += sizeof(gbuint32); le_write32(&workbuffer[position],count); position += sizeof(gbuint32); @@ -363,8 +405,8 @@ vitosmt_write(void) rewind(ofs); if (fwrite(workbuffer,vitosmt_headersize,1,ofs)!=1) { - fatal("%s writing output file. Error was '%s'.\n", - MYNAME, strerror(errno)); + fatal("%s (%d) writing output file. Error was '%s'.\n", + MYNAME, __LINE__, strerror(errno)); } xfree(workbuffer); -- 2.30.2